import Vue from 'vue'
import MessageComp from './Message.vue'

const MessageCtor = Vue.extend(MessageComp)

const Message = (options) => {
  const instance = new MessageCtor({
    // 给组件传递数据
    data: options
  })
  // 表示挂载组建，这个挂载后的结果会放到$el
  instance.$mount()
  document.body.appendChild(instance.$el)

  instance.visible = true
}

;['success', 'error', 'warning'].forEach((type) => {
  Message[type] = function (options) {
    options.type = type
    return Message(options)
  }
})

export { Message }
